
package com.fulihui.wgj.config;

import com.fulihui.wgj.config.properties.JedisPoolProps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author: Levon
 * @date: 2018-06-20 17:14
 */
@Configuration
@EnableConfigurationProperties({JedisPoolProps.class})
public class RedisConfig {

    @Autowired
    JedisPoolProps jedisPoolProps;

    @Bean
    public JedisPoolConfig jedisPoolConfig() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(jedisPoolProps.getMaxidle());
        poolConfig.setMaxTotal(jedisPoolProps.getMaxtotal());
        return poolConfig;
    }

    @Bean
    public JedisPool jedisPool(JedisPoolConfig jedisPoolConfig) {
        return new JedisPool(jedisPoolConfig, jedisPoolProps.getHost(),
                jedisPoolProps.getPort(), jedisPoolProps.getTimeout(),
                jedisPoolProps.getPassword(), jedisPoolProps.getDatabase());
    }

}
